@workover/mcp 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +12 -2
  2. package/index.mjs +29 -2
  3. package/lib.mjs +76 -4
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @workover/mcp
2
2
 
3
- An [MCP](https://modelcontextprotocol.io) server for [Workover](https://workover.dev) — lets Claude Code (and other MCP clients) read your Workover documents and propose edits you review.
3
+ An [MCP](https://modelcontextprotocol.io) server for [Workover](https://workover.dev) — lets Claude Code (and other MCP clients) read your Workover documents, create new ones, and propose edits you review.
4
4
 
5
5
  ## Setup
6
6
 
@@ -24,11 +24,21 @@ That's it. Ask Claude Code things like *"read my Workover doc about onboarding a
24
24
  - `workover_search_docs(query)` — find documents by title/content
25
25
  - `workover_read_doc(docId)` — read a document's text
26
26
  - `workover_list_projects()` — list your projects
27
+ - `workover_create_doc(projectId, title, markdown)` — create a document with its content written in
28
+ - `workover_upload_image(docId, path, alt)` — put a local image into a document's media
27
29
  - `workover_propose_edit(docId, markdown, note)` — propose a revised version (rendered as suggestions; never applied or published automatically)
30
+ - `workover_edit_doc(docId, markdown, note)` — edit a document directly, no review step. Needs `workover login --write`
31
+
32
+ Everything the MCP server can do, the CLI can do too (`workover doc create|read|propose|write|list|search`). That is deliberate: a newly-registered MCP server is not available in the session that registered it, so an agent that finds mid-task that it needs Workover has no way in until it restarts. A CLI subcommand works immediately.
28
33
 
29
34
  ## Safety
30
35
 
31
- The server authenticates with the token from `workover login` and is **read + propose only**. It cannot publish to WordPress, change your account, or apply changes without you. Every edit is a suggestion a human accepts, and only a human publishes. Revoke access anytime in **Workover → Settings → Developer**.
36
+ The server authenticates with the token from `workover login`. By default it is **read + propose only**: it cannot publish to WordPress, change your account, or apply changes without you. Every edit is a suggestion you accept, and only a person publishes. Revoke access anytime in **Workover → Settings → Developer**.
37
+
38
+ Two deliberate exceptions, both of which still stop short of publishing:
39
+
40
+ - **A new document's first content is written in, not proposed.** `workover_create_doc` creates the document and its body together. A document that did not exist a second ago has no text to protect, and asking you to accept your own content against an empty page is a review step with nothing in it.
41
+ - **`workover_edit_doc` edits an existing document directly** — for when you are working alongside the agent and say "make that change", rather than getting fifty tracked suggestions to click through for an edit you just asked for. It only works if you granted it: sign in with `workover login --write`, and the browser tells you exactly that before you approve. Without it the tool returns a permission error and proposing is the way through.
32
42
 
33
43
  ## Configuration
34
44
 
package/index.mjs CHANGED
@@ -64,7 +64,7 @@ const TOOLS = [
64
64
  {
65
65
  name: 'workover_create_doc',
66
66
  description:
67
- "Create a new document in a Workover project (find the projectId with workover_list_projects). The body is added as a proposal, so it appears as tracked-change suggestions for the person to review and accept when they open the doc — nothing is published. Returns the new document's id and URL.",
67
+ "Create a new document in a Workover project (find the projectId with workover_list_projects), with its content written straight in — a brand-new document has no prior text, so there is nothing to review the first body against. Later changes to it go through workover_propose_edit as suggestions. Nothing is published to WordPress. Returns the new document's id and URL.",
68
68
  inputSchema: {
69
69
  type: 'object',
70
70
  properties: {
@@ -96,6 +96,30 @@ const TOOLS = [
96
96
  required: ['docId', 'path'],
97
97
  },
98
98
  },
99
+ {
100
+ name: 'workover_edit_doc',
101
+ description:
102
+ "Edit a Workover document DIRECTLY, replacing its body with no suggestions for anyone to review. Use this ONLY when the person has asked for the change to be made — working together on a document they have open, 'just make that edit'. Otherwise use workover_propose_edit, which is the default and leaves them something to accept or reject. Read the document first (workover_read_doc) and provide the FULL revised document: this REPLACES the body, so anything omitted is deleted. Requires a token from `workover login --write`; without that scope this returns a permission error and proposing is the way through. Never publishes to WordPress.",
103
+ inputSchema: {
104
+ type: 'object',
105
+ properties: {
106
+ docId: {
107
+ type: 'number',
108
+ description: 'The numeric id of the document to edit (not a URL handle).',
109
+ },
110
+ markdown: {
111
+ type: 'string',
112
+ description:
113
+ 'The complete document as markdown. It replaces the current body in full — anything left out is removed.',
114
+ },
115
+ note: {
116
+ type: 'string',
117
+ description: 'A short summary of what you changed, kept in the audit log.',
118
+ },
119
+ },
120
+ required: ['docId', 'markdown'],
121
+ },
122
+ },
99
123
  {
100
124
  name: 'workover_propose_edit',
101
125
  description:
@@ -123,7 +147,10 @@ const TOOLS = [
123
147
  ];
124
148
 
125
149
  const telemetry = telemetryEnabled(process.env, { auth });
126
- const VERSION = '0.2.0';
150
+ // Keep in step with package.json. It is what every telemetry event is stamped with, so a stale
151
+ // value here does not break anything — it quietly attributes this release's behaviour to an older
152
+ // one, which is worse, because the numbers still look fine.
153
+ const VERSION = '0.4.0';
127
154
 
128
155
  const server = new Server(
129
156
  { name: 'workover', version: '0.1.0' },
package/lib.mjs CHANGED
@@ -86,6 +86,19 @@ export const badIdErr = (kind, got) =>
86
86
  `"${got}" isn't a ${kind} id. Pass the numeric id (e.g. 12345) — the one workover_search_docs prints as "#12345" or workover_list_projects as "#7". A handle from a document URL won't work here.`,
87
87
  );
88
88
 
89
+ /**
90
+ * Whether a just-created document came back with its body already in it.
91
+ *
92
+ * The create call sends `markdown`, and a Workover that understands it writes the content directly
93
+ * — there is no prior text on a document one call old, so there is nothing for a human to accept or
94
+ * reject. An older API validates the body with a whitelist and silently DROPS the field, returning
95
+ * a perfectly successful empty document. That is the failure worth catching: the content would be
96
+ * gone with nothing said. So the answer is read off the response rather than assumed, and the
97
+ * caller falls back to proposing when it is no.
98
+ */
99
+ export const contentCommitted = (doc) =>
100
+ typeof doc?.content === 'string' && doc.content.trim().length > 0;
101
+
89
102
  /** Map an image file extension to its mime type (defaults to png). */
90
103
  export const mimeForExt = (ext) => {
91
104
  const e = String(ext || '').toLowerCase();
@@ -106,7 +119,16 @@ export function makeApi({ auth, fetchImpl = fetch }) {
106
119
  });
107
120
  if (res.status === 401)
108
121
  throw new Error('Your Workover login expired or was revoked. Run `workover login`.');
109
- if (res.status === 403) throw new Error('This token isn’t allowed to do that.');
122
+ if (res.status === 403) {
123
+ // The API's own sentence when it sent one. A scope refusal names the scope and the command
124
+ // that grants it ("Re-run `workover login --write`"), which is the difference between an
125
+ // agent that can fix this and one that reports a flat "not allowed" and stops.
126
+ const detail = await res
127
+ .json()
128
+ .then((body) => (typeof body?.message === 'string' ? body.message : ''))
129
+ .catch(() => '');
130
+ throw new Error(detail || 'This token isn’t allowed to do that.');
131
+ }
110
132
  if (!res.ok) throw new Error(`Workover API error (${res.status}).`);
111
133
  return res.json();
112
134
  }
@@ -148,7 +170,25 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
148
170
  if (docId === null) return badIdErr('document', args.docId);
149
171
  const d = await api(`/project/doc/${docId}`);
150
172
  if (!d || !d.id) return err(`Document ${docId} not found (or no access).`);
151
- const body = d.bodyText || stripHtml(d.content) || '(empty document)';
173
+ // Prefer the LIVE body, which is the only one with images in it.
174
+ //
175
+ // `bodyText` is plain text kept for search and `content` is only written on a WordPress
176
+ // import, so a document written in the editor read as empty here, and one made of
177
+ // screenshots read as empty EXACTLY — plain text of an image is nothing. An agent that
178
+ // reads "(empty document)" and then edits is working from a blank page that is not blank.
179
+ //
180
+ // Best-effort: an api that predates this route still answers the row.
181
+ let live = null;
182
+ try {
183
+ live = await api(`/project/doc/${docId}/content`);
184
+ } catch {
185
+ live = null;
186
+ }
187
+ const body =
188
+ live?.markdown?.trim() ||
189
+ d.bodyText ||
190
+ stripHtml(d.content) ||
191
+ '(empty document)';
152
192
  return text(`# ${d.title || 'Untitled'} (id ${d.id})\n\n${body}`);
153
193
  }
154
194
  if (name === 'workover_list_projects') {
@@ -163,14 +203,28 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
163
203
  if (!title || !md) return err('Provide both a `title` and the body as `markdown`.');
164
204
  const projectId = rowId(args.projectId);
165
205
  if (projectId === null) return badIdErr('project', args.projectId);
166
- const doc = await apiPost(`/project/${projectId}/documents`, { title });
206
+ // The body goes WITH the create. A document this call brought into existence has no prior
207
+ // text to protect, so its first content is written directly rather than queued as
208
+ // suggestions for the person to accept against an empty page.
209
+ const doc = await apiPost(`/project/${projectId}/documents`, {
210
+ title,
211
+ markdown: md,
212
+ });
167
213
  if (!doc?.id) return err('Could not create the document.');
214
+ if (contentCommitted(doc)) {
215
+ return text(
216
+ `Created "${title}" (document #${doc.id}) with the content written in — no review step, because it is a new document.${doc.documentUrl ? `\n${doc.documentUrl}` : ''}\n\nFurther changes to it go through workover_propose_edit, which the person accepts or rejects. Nothing is published to WordPress either way.`,
217
+ );
218
+ }
219
+ // This Workover predates create-with-content and dropped the field, leaving an empty
220
+ // document. Propose the body instead of losing it, and say which of the two happened —
221
+ // "created" over an empty page reads like success right up until somebody opens it.
168
222
  const proposal = await apiPost(`/project/doc/${doc.id}/propose`, {
169
223
  markdown: md,
170
224
  source: 'Claude Code',
171
225
  });
172
226
  return text(
173
- `Created "${title}" (document #${doc.id}) and added the content as suggestions to review.${proposal?.documentUrl ? `\n${proposal.documentUrl}` : ''}\n\nOpen it in Workover to accept or reject the changes — nothing is published.`,
227
+ `Created "${title}" (document #${doc.id}). This Workover can't write a new document's content directly, so the body is waiting as suggestions instead.${proposal?.documentUrl ? `\n${proposal.documentUrl}` : ''}\n\nOpen it in Workover and accept them — the document is empty until you do.`,
174
228
  );
175
229
  }
176
230
  if (name === 'workover_upload_image') {
@@ -200,6 +254,24 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile }
200
254
  `Uploaded. Reference it in the document markdown:\n\n![${args.alt || 'screenshot'}](${url})`,
201
255
  );
202
256
  }
257
+ if (name === 'workover_edit_doc') {
258
+ const md = String(args.markdown || '').trim();
259
+ if (!md) return err('Provide the full revised document as `markdown`.');
260
+ const docId = rowId(args.docId);
261
+ if (docId === null) return badIdErr('document', args.docId);
262
+ const res = await apiPost(`/project/doc/${docId}/content`, {
263
+ markdown: md,
264
+ note: args.note ? String(args.note) : undefined,
265
+ source: 'Claude Code',
266
+ });
267
+ return text(
268
+ `Edited document #${docId} directly — the new text is in the document and there is nothing to accept.${res?.documentUrl ? `\n${res.documentUrl}` : ''}${
269
+ res?.replacedCharacters
270
+ ? `\n\nReplaced ${res.replacedCharacters} characters of existing text.`
271
+ : ''
272
+ }`,
273
+ );
274
+ }
203
275
  if (name === 'workover_propose_edit') {
204
276
  const md = String(args.markdown || '').trim();
205
277
  if (!md) return err('Provide the full revised document as `markdown`.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/mcp",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Workover MCP server — let Claude Code and other MCP clients read and cowork on your Workover documents.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ScaleMath",